<template>
    <el-dialog
      v-model="outerVisible"
      width="500"
      title="创建新场景"
      append-to-body
    >
      <el-form :model="sceneForm" label-width="100px">
        <el-form-item label="场景名称" prop="name">
          <el-input v-model="sceneForm.name" placeholder="请输入场景名称"/>
        </el-form-item>
        
        <el-form-item label="初始视角">
          <el-row :gutter="10">
            <el-col :span="8">
              <el-input-number v-model="sceneForm.longitude" :min="-180" :max="180" :step="0.1"/>
              <span class="form-unit">经度</span>
            </el-col>
            <el-col :span="8">
              <el-input-number v-model="sceneForm.latitude" :min="-90" :max="90" :step="0.1"/>
              <span class="form-unit">纬度</span>
            </el-col>
            <el-col :span="8">
              <el-input-number v-model="sceneForm.height" :min="1000" :max="10000000" :step="1000"/>
              <span class="form-unit">高度</span>
            </el-col>
          </el-row>
        </el-form-item>

      </el-form>
      <template #footer>
        <el-button @click="createVisible = false">取消</el-button>
        <el-button type="primary" @click="handleCreate">创建</el-button>
      </template>
    </el-dialog>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage } from 'element-plus'

const outerVisible = ref(false)
const createVisible = ref(false)
const openVisible = ref(false)
const insertVisible = ref(false)
const shouceVisible = ref(false)
const sceneForm = ref({
  name: '',
  longitude: 116.4,
  latitude: 39.9,
  height: 15000000
})

const router = useRouter()

const handleCreate = () => {
  if (!sceneForm.value.name) {
    ElMessage.error('请输入场景名称')
    return
  }
  
  createVisible.value = false
  outerVisible.value = false
  localStorage.setItem('currentScene', JSON.stringify(sceneForm.value))
  // 创建成功后强制刷新页面
  window.location.reload()
}

const showAndInit = () => {
    outerVisible.value = true
}

defineExpose({
    showAndInit,
})
</script>

<style lang="scss">
/* 基础对话框样式 */
.el-dialog {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  border-radius: 12px;
  background: #ffffff;
  width: 600px !important; /* 固定外层宽度 */
}

.el-dialog__header {
  padding: 16px 24px;
  border-bottom: 1px solid #f0f2f5;
}

.el-dialog__title {
  font-size: 18px;
  font-weight: 500;
  color: #2c3e50;
}

.el-dialog__footer {
  padding: 16px 24px;
  border-top: 1px solid #f0f2f5;
  justify-content: flex-end;
  gap: 8px;
}

/* 按钮通用样式 */
.el-button {
  min-width: 80px;
  height: 36px;
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.2s ease;
}

/* 操作按钮区域（创建新场景等按钮） */
.dialog-content {
  padding: 24px;
  display: flex;
  gap: 12px;
}

.action-btn {
  color: #409eff;
  border: 1px solid #e4ebff;
  background: #f5f9ff;

  &:hover {
    background: #e4ebff;
    transform: translateY(-1px);
  }
}

.el-button--primary.action-btn {
  color: #fff;
  background: #409eff;
  border-color: #409eff;

  &:hover {
    background: #3a8ee6;
    border-color: #3a8ee6;
  }
}

/* 子对话框样式（创建/打开等内部对话框） */
.el-dialog + .el-dialog {
  margin-top: 16px;
  width: 500px !important;
}

/* 表单样式 */
.el-form-item {
  margin-bottom: 18px;

  .el-input__inner,
  .el-input-number__wrapper {
    height: 40px;
    border: 1px solid #e4ebff;
    border-radius: 8px;

    &:focus {
      border-color: #409eff;
      box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.1);
    }
  }
}

.form-unit {
  margin-left: 8px;
  color: #606266;
  font-size: 12px;
}
</style>